<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <link href="../css/aui.css" rel="stylesheet" type="text/css"/>
    <link href="../css/aui-iconfont.css" rel="stylesheet"/>
    <link href="../css/index.css" rel="stylesheet" type="text/css"/>
    <link rel="stylesheet" href="../js/jstree/themes/default/style.min.css" />
    <style type="text/css">
        textarea{
            height: 300px;
        }
        body{
            background: #ffffff;
        }
        .tips{
            padding: 6px;
            font-size: 10px;
        }
        .smallfont{
            font-size: 10px;
        }
        .scinp{
            width: 100px!important;
        }
    </style>
</head>
<body>
<div class="aui-tips aui-tips-info hide" id="tips">
    <div class="aui-tips-content">
        <div class="aui-col-xs-12">
            <div class="aui-col-xs-11">
                <i class="aui-iconfont aui-icon-info"></i>
                <span id="tip_msg"></span>
            </div>
            <div style="text-align:center;float:right;width: 15px;height: 100%;" onclick="hideTips();">
                <i class="aui-iconfont aui-icon-close"></i>
            </div>
        </div>
    </div>
</div>
<div class="aui-col-xs-12 aui-text-center">
    <div class="aui-col-xs-3">
        <div class="tab select" onclick="select(this,1)">生成界面</div>
    </div>
    <div class="aui-col-xs-3">
        <div class="tab" onclick="select(this,2)">API管理</div>
    </div>
    <div class="aui-col-xs-3">
        <div class="tab" onclick="select(this,3)">JSON格式化</div>
    </div>
    <div class="aui-col-xs-3">
        <div class="tab" onclick="select(this,4)">工具</div>
    </div>
</div>
 

<div class="content select" id="tab1">
    <div id="tab1_context"></div>
</div>
<div class="content" id="tab2">
    <div class="layout" id="tab2_tools">
        <button class="aui-btn aui-btn-primary" onclick="bySwagger()">从swagger获取</button>
        <button class="aui-btn aui-btn-info" onclick="byFindler();">从 findler 获取</button>
        <button onclick="generateCodeAll();">生成全部代码</button>
        <button class="aui-btn aui-btn-default" id="hasDelBtn" onclick="hasDelList();">已屏蔽列表</button>
        <button class="aui-btn aui-btn-info" onclick="byFindler();">ROOT URL管理</button>
        <button class="aui-btn aui-btn-info" onclick="byFindler();">当前使用项目</button>
        <p id="tab2_tips"></p>
    </div>
    <div class="layout" style="height: 50px" id="tab2_tools2">
        <div class="aui-col-xs-12">
            <div class="aui-col-xs-10">
                <input type="checkbox" class="aui-input aui-input-select"/>全选
                <button class="aui-btn aui-btn-primary" onclick="generateCodeBySelect('')">生成</button>
                <button class="aui-btn aui-btn-warning" onclick="delApiBySelect('')">屏蔽</button>
                <button class="aui-btn" id="selectSource" onclick="showSelectSource();">数据源:全部</button>
            </div>
            <div class="aui-col-xs-2 aui-pull-right">
                <button class="aui-btn aui-btn-success">添加</button>
            </div>
        </div>
    </div>
    <div id="tab2_context"></div>
</div>
<div class="content" id="tab3">
    <textarea id="log" style="width: 100%;height: 300px;"></textarea>
    <button class="aui-btn aui-btn-success" onclick="getAsLog();">格式化</button>
    <div id="tab3_context"></div>
</div>
<div class="content" id="tab4">
    <div id="tab4_context"></div>
    <div class="layout">
        <div class="edit_group">
            <div class="edit">
                <input type="text" placeholder="请输入内容" id="qrcode"/>
            </div>
            <div class="edit_btn" onclick="parseQrcode();">生成二维码</div>
        </div>
        <div class="tips">
            <a href="javascript:qrcodeHistory();" class="aui-btn smallfont">历史记录</a>
            <a href="javascript:autoCode();" class="aui-btn smallfont">随机生成</a>
            <a href="javascript:removeAutoCode();" class="aui-btn smallfont">停止</a>
        </div>
        <div id="qrcode_area">

        </div>
    </div>

    <div class="layout">
        <div class="edit_group">
            <div class="edit">
                <input type="text" disabled placeholder="请选择应用..." id="fileSign"/>
            </div>
            <div class="edit_btn" onclick="fileSign();">应用签名</div>
        </div>
        <div class="tips">
            生成唯一签名用于应用更新时验证文件一致性
        </div>
    </div>

    <div class="layout">
        <div class="edit_group">
            <div class="edit">
                <input type="text" placeholder="请输入图片文件名(为空则使用文件名)" id="addIcon"/>
            </div>
            <div class="edit_btn" onclick="addIcon();">添加图标</div>
        </div>
        <div id="add_icon_tips" class="tips">

        </div>
    </div>

    <div class="layout">
            <textarea id="page_group" style="width: 100%;height: 200px;"></textarea>
            <input class="scinp" type="text" id="page_id" placeholder="请输入pid"/>
            <input class="scinp"  type="text" id="page_title" placeholder="请输入标题" />
            <input class="scinp" type="text" id="page_class" placeholder="请输入类名" />
            <input class="scinp" type="text" id="page_column" placeholder="请输入字段" />
            <select class="scinp" id="page_type">
                <option value="0" selected>默认</option>
                <option value="1">表格</option>
            </select>

            <div class="btn-group">
                <button class="aui-btn" onclick="addGroup();">添加页面组</button>
                <button class="aui-btn aui-btn-primary" onclick="generateFormPage();">生成代码</button>
            </div>
       <div style="width: 100%;height: 20px;"></div>


        <textarea id="page_form" style="width: 100%;height: 200px;"></textarea>
            <select class="scinp" id="form_type">
                <option value="0">默认输入框</option>
                <option value="1">默认选择框</option>
                <option value="2">日期选择框</option>
                <option value="3">多行文本输入框</option>
                <option value="4">单选框</option>
                <option value="5">标题栏</option>
                <option value="6">图片</option>
                <option value="7">视频</option>
                <option value="8">单行表格查看</option>
                <option value="9">带按钮的选择框</option>
                <option value="10">开关</option>
                <option value="11">按钮组</option>
                <option value="12">选择框 带按钮 可编辑文本</option>
                <option value="13">数字输入框</option>
                <option value="14">图文框</option>
            </select>
        <input class="scinp"  type="text" id="form_id" placeholder="请输入id" />
        <input class="scinp"  type="text" id="form_title" placeholder="请输入标题" />
        <input class="scinp" type="text" id="form_hint" placeholder="请输入默认提示" />
            <select class="scinp" id="form_enable">
                <option value="true" selected="selected">启用</option>
                <option value="false">禁止</option>
            </select>
            <select class="scinp" id="form_required">
                <option value="true">必填</option>
                <option value="false" selected="selected">选填</option>
            </select>
            <input class="scinp" id="form_danw" type="text" placeholder="请输入单位" />
            <input class="scinp" type="text" id="form_length" placeholder="请输入最大长度" />
            <input class="scinp" type="text" id="form_regexVerify" placeholder="请输入正则验证，多个用;分割" />
            <input class="scinp" type="text" id="form_regexTips" placeholder="请输入正则验证提示，多个用;分割" />
            <input class="scinp" type="text" id="form_class" placeholder="请输入类名" />
        <div class="btn-group">
            <button class="aui-btn" onclick="addForm();">添加表单</button>
            <button class="aui-btn aui-btn-primary" onclick="generateForm();">生成代码</button>
        </div>
    </div>
</div>
<script src="../js/template.js" type="text/javascript"></script>
<script src="../js/api.js" type="text/javascript"></script>
<script src="../js/jquery.min.js" type="text/javascript"></script>
<script src="../js/jstree/jstree.min.js" type="text/javascript"></script>
<script src="../js/qrcode.min.js" type="text/javascript"></script>
<script id="apiDom" type="text/html">
    {{ for(var a in it) { }}
        <div class="layout" id="api_layout_{{=a}}">
            <div class="aui-col-xs-12">
                <div class="aui-col-xs-8">
                    <div class="input aui-ellipsis-1">
                    <input type="checkbox" class="aui-input aui-input-select"/>{{=it[a].name}}
                    </div>
                    </div>
                <div class="aui-col-xs-4  aui-pull-right">
                    <div class="aui-btn aui-btn-primary" onclick="generateCodeByGroupId('{{=it[a].id}}')">生成</div>
                    {{? it[a].del }}
                    <div class="aui-btn aui-btn-danger" onclick="delApiByGroupId('{{=a}}','{{=it[a].id}}')">删除</div>
                    {{??}}
                    <div class="aui-btn aui-btn-warning" onclick="delApiByGroupId('{{=a}}','{{=it[a].id}}')">屏蔽</div>
                    {{?}}
                    <div class="aui-btn aui-btn-success"  onclick="toggleLayout(this,'{{=a}}')">展开</div>
                </div>
            </div>
            <div style="width: 100%;height: 25px;"></div>
            <div id="api_dom_{{=a}}" class="hide">
            {{ for(var i in it[a].apiActions) { }}
                <div  class="api_dom"  id="api_dom_{{=a}}_{{=i}}">
                    <div class="api_url">{{=it[a].apiActions[i].url || ''}}</div>
                    <div class="aui-col-xs-12">
                        别名<input type="text" id="api_alias_{{=a}}_{{=i}}" value="{{=it[a].apiActions[i].alias || ''}}"/>
                        <input type="button" class="aui-btn" value="修改" onclick="changeAlias('api_alias_{{=a}}_{{=i}}','{{=it[a].apiActions[i].id}}');"/>
                    </div>
                    <div class="btn-group">
                        {{? it[a].apiActions[i].del }}
                            <div class="aui-btn aui-btn-success" onclick="viewApi('{{=a}}','{{=i}}')">查看</div>
                            <div class="aui-btn aui-btn-primary" onclick="generateCode('{{=it[a].apiActions[i].id}}')">生成</div>
                            <div class="aui-btn aui-btn-warning" onclick="delApi('{{=a}}','{{=i}}','{{=it[a].apiActions[i].id}}')">取消屏蔽</div>
                            <div class="aui-btn aui-btn-danger" onclick="delApi('{{=a}}','{{=i}}','{{=it[a].apiActions[i].id}}')">删除</div>
                        {{??}}
                            <div class="aui-btn aui-btn-success" onclick="viewApi('{{=a}}','{{=i}}')">查看</div>
                            <div class="aui-btn aui-btn-info" onclick="remark('{{=a}}','{{=i}}')">备注</div>
                            <div class="aui-btn aui-btn-primary" onclick="generateCode('{{=it[a].apiActions[i].id}}')">生成</div>
                            <div class="aui-btn aui-btn-warning" onclick="delApi('{{=a}}','{{=i}}','{{=it[a].apiActions[i].id}}')">屏蔽</div>
                            <div class="aui-btn aui-btn-success" onclick="runApi('{{=a}}','{{=i}}')">执行</div>
                        {{?}}
                    </div>
                    <div id="tips_{{=it[a].apiActions[i].id}}"></div>
                </div>
            {{ } }}
            </div>
        </div>
    {{ } }}
</script>

<script id="apiLog" type="text/html">
    {{ for(var a in it) { }}
    <div  class="layout api_log">
        <textarea  style="width: 100%;height: 300px;"> {{=it[a].text || ''}}</textarea>
    </div>
    {{ } }}
</script>
<!--swagger api 输入窗-->
<script id="swagger_win" type="text/html">
    <div class="swagger_body">
        <textarea class="aui-input big_input" id="swagger_url"></textarea>
        <div class="aui-col-xs-12">
            <div class="aui-col-xs-9 aui-text-left">
                <div id="swagger-tips">
                   请输入swagger api的json地址
                </div>
            </div>
            <div class="aui-col-xs-3 aui-text-right">
                <button class="aui-btn" onclick="getSwaggerHistory();">历史记录</button>
                <button class="aui-btn aui-btn-primary" onclick="getSwaggerApi();">确定</button>
            </div>
        </div>
    </div>
</script>
<!--历史记录操作窗-->
<script id="history_win" type="text/html">

</script>
<script id="view_api_win" type="text/html">
    <div class="aui-col-xs-12">
        <div class="aui-col-xs-3">地址:</div>
        <div class="aui-col-xs-9">
            <input type="text" value="{{=it.url}}" id="api_url"/>
        </div>
    </div>
    <div class="aui-col-xs-12">
        <div class="aui-col-xs-3">请求参数:</div>
        <div class="aui-col-xs-9"><textarea id="api_request">{{=it.request||'{}'}}</textarea></div>
    </div>
    <div class="aui-col-xs-12">
        <div class="aui-col-xs-3">返回参数:</div>
        <div class="aui-col-xs-9"><textarea id="api_respone">{{=it.respone||'{}'}}</textarea></div>
    </div>
    <div class="aui-col-xs-12">
        <div class="aui-col-xs-3">备注:</div>
        <div class="aui-col-xs-9"><textarea id="api_remark">{{=it.remark||''}}</textarea></div>
    </div>
    <div class="aui-col-xs-12">
        <div class="aui-col-xs-8" id="view_tips"></div>
        <div class="aui-col-xs-4">
            <button class="aui-btn aui-btn-success" onclick="saveInfo();">保存</button>
        </div>
    </div>
</script>
<script id="select_source" type="text/html">
    {{ for(var i in it) { }}
        <div class="layout printer" id="source_layout_{{=it[i].id}}">
            <div class="btn-group">
                <div class="aui-text-left"> {{=it[i].domain}}</div>
                <div style="float: right;">
                <button class="aui-btn aui-btn-success" onclick="selectSource('{{=it[i].domainMd5}}','{{=it[i].domain}}')">选择</button>
                <button class="aui-btn aui-btn-danger" onclick="deleteSource('{{=it[i].id}}')">删除</button>
                </div>
            </div>
        </div>
    {{ } }}
</script>
<script id="swagger_history" type="text/html">
    {{ for(var i in it) { }}
    <div class="layout printer" id="swagger_history_layout_{{=i}}">
        <div class="btn-group">
            <div class="aui-text-left">{{=it[i].value}}</div>
            <button class="aui-btn aui-btn-success" onclick="selectSwaggerUrl('{{=it[i].value}}')">选择</button>
            <button class="aui-btn aui-btn-danger" onclick="deleteSwaggerUrl('{{=it[i].id}}')">删除</button>
        </div>
    </div>
    {{ } }}
</script>
 <script type="text/javascript">

     function addForm(){
         var form_id = $api.val($api.byId("form_id"));
         var form_type = $api.val($api.byId("form_type"));
         var form_title = $api.val($api.byId("form_title"));
         var form_hint = $api.val($api.byId("form_hint"));
         var form_enable = $api.val($api.byId("form_enable"));
         var form_required= $api.val($api.byId("form_required"));
         var form_danw = $api.val($api.byId("form_danw"));
         var form_length = $api.val($api.byId("form_length"));
         var form_regexVerify = $api.val($api.byId("form_regexVerify"));
         var form_regexTips = $api.val($api.byId("form_regexTips"));
         var form_class = $api.val($api.byId("form_class"));
         var json = $api.val($api.byId("page_form"));
         if(json){
             try{
                 json = JSON.parse(json);
             }catch (e) {
                 json = {};
             }
         }else{
             json = {};
         }
         json.className=form_class;
         var d = {};
         d.id = form_id;
         d.type = form_type;
         d.title = form_title;
         d.hint = form_hint;
         d.enabled = form_enable;
         d.required = form_required;
         d.danw = form_danw;
         d.length = form_length;
         d.regexVerify  = form_regexVerify;
         d.regexTips = form_regexTips;
        if(!json.forms){
            json.forms = new Array();
        }
        json.forms.push(d);
        $api.val($api.byId("page_form"),JSON.stringify(json));
     }
     function generateForm(){
         var json = $api.val($api.byId("page_form"));
         $api.generateForm(json,function(ret,err){
             if(ret){
                 tips(ret);
             } else{
                 tips(err.message);
             }
         });
     }

     function addGroup(){
         var page_id = $api.val($api.byId("page_id"));
         var page_title = $api.val($api.byId("page_title"));
         var page_class = $api.val($api.byId("page_class"));
         var page_column = $api.val($api.byId("page_column"));
         var json = $api.val($api.byId("page_group"));
         if(json){
             try{
                 json = JSON.parse(json);
             }catch (e) {
                 json = new Array();
             }
         }else{
            json = new Array();
         }
         var d = {};
         d.page_id = page_id;
         d.page_title = page_title;
         d.page_class = page_class;
         d.page_column = page_column;
         json.push(d);
         $api.val($api.byId("page_group"),JSON.stringify(json));
     }
     function generateFormPage() {
         var json = $api.val($api.byId("page_group"));
         $api.generateFormPage(json,function(ret,err){
             if(ret){
                 tips(ret);
             } else{
                 tips(err.message);
             }
         });
     }

     function toggleLayout(obj,a){
         var dom = $api.byId('api_dom_'+a);
         if($api.hasCls(dom,'hide')){
             $api.removeCls(dom,'hide');
             $api.html(obj,"收起");
         }else{
             $api.addCls(dom,'hide');
             $api.html(obj,"展开");
         }
     }
     var hasDel = false ;
     function hasDelList(){
         var btn = $api.byId('hasDelBtn');
         if(hasDel){
             $api.removeCls(btn,'aui-btn-warning');
             $api.addCls(btn,'aui-btn-default');
             hasDel = false;
         }else{
             $api.removeCls(btn,'aui-btn-default');
             $api.addCls(btn,'aui-btn-warning');
             hasDel = true;
         }
         getApiInfo();
     }
     function getSwaggerHistory(){
         if($api.disableWin){
             return;
         }
         $api.getStroageList('swagger_url',null,function(ret,err){
             if(ret){
                 $api.showWin('swagger_history','请选择历史记录',ret);
             }
         });
     }
     function deleteSwaggerUrl(id){
         this.id = id;
         $api.rmStorage(id,function(ret,err){
             if(ret){
                 $api.remove($api.byId('swagger_history_layout_'+id));
             }else{

             }
         });
     }
     //修改别名
     function changeAlias(dom,id){
         tips(dom+"/"+id);
     }
     function selectSwaggerUrl(value){
         $api.val($api.byId('swagger_url'),value);
         $api.hideWin();
     }
     function deleteSource(id){
         $api.deleteSource(id,function(ret,err){
            if(ret){
                $api.remove($api.byId("source_layout_"+id));
                $api.hideWin();
                tips(ret);
                getApiInfo();
            }else{
                tips(err);
            }
         });
     }
     function selectSource(id,name){
        this.selectDomain = id;
         getApiInfo();
         $api.hideWin();
         if(name.indexOf("-")!=-1){
             var n = name.split('-');
             name = n[n.length-1];
         }
         $api.html($api.byId("selectSource"),'数据源:'+name)
     }
     function showSelectSource(){
         $api.getDomainInfo(function(ret,err){
             if(ret){
                 $api.showWin('select_source','请选择数据源',ret);
             }else{

             }
         });
     }
     var tempDetail;
     function viewApi(a,i){
         if(!apiInfos){
             return;
         }
         tempDetail= apiInfos[a].apiActions[i];
         var url = tempDetail.url.split("/");
         $api.showWin('view_api_win',tempDetail.title||url[url.length-1],tempDetail);
     }
     function saveInfo(){
         var id = tempDetail.id;
         var url = $api.val($api.byId("api_url"));
         var req =  $api.val($api.byId("api_request"));
         var res =  $api.val($api.byId("api_respone"));
         var remark =  $api.val($api.byId("api_remark"));
         $api.saveApi(id,url,req,res,remark,function(ret,err){
            if(ret){
                tips("保存成功!")
            } else{
                tips(err);
            }
         });
     }
     function remark(a,i){

     }
     var id;
     function generateCode(id){
         this.id = id;
         $api.generateCode(id,function(ret,err){
             if(ret){
                 $api.html($api.byId("tips_"+id),ret);
             }else{
                 $api.html($api.byId("tips_"+id),err.message);
             }
         });
     }
     var gid,cid;
     function delApiByGroupId(gid,id){
         this.gid = gid;
         $api.delApiByGroupId(id,function(ret,err){
             if(ret){
                 $api.remove($api.byId("api_layout_"+gid));
             }else{
                 alert(JSON.stringify(err));
             }
         });
     }
     function delApi(gid,cid,id){
         this.gid = gid;
         this.cid = cid;
         $api.delApi(id,function(ret,err){
            if(ret){
                $api.remove($api.byId("api_dom_"+gid+"_"+cid));
            }else{

            }
         });
     }

     function bySwagger(){
         $api.showWin('swagger_win','请输入swagger api 的json地址');
        $api.getStorage("swagger_url",function(ret,err){
             if(ret){
                 $api.val($api.byId("swagger_url"),ret);
             }
         });
     }
     function getSwaggerApi(){
         var url = $api.val($api.byId("swagger_url"));
         url = url.replace(/\s+/g,"");
         if(!url){
             $api.showTips('swagger-tips','url地址不能为空!');
             return;
         }
        getData(url);
     }
     function getData(url){
         if($api.disableWin){
             return;
         }
         $api.showTips('swagger-tips','正在加载数据...');
         $api.ajax(url,'get',{},'text',function(data,errcode){
             if(data){
                 $api.setStorage("swagger_url",url);
                 $api.showTips('swagger-tips','正在解析数据...');
                 $api.disableWin = true;
                 $api.call("analysisSwagger",data,function(res,err){
                     if(res){
                         $api.disableWin = false;
                         $api.showTips('swagger-tips',res);
                         setTimeout(function(){
                             $api.hideWin();
                             getApiInfo();
                         },2000);
                     }else{
                         if(err.code==0){
                             $api.disableWin = false;
                         }
                         $api.showTips('swagger-tips',err.message);
                     }
                 });
             }else{
                 $api.showTips('swagger-tips','网络请求失败,状态码:'+errcode);
             }

         });
     }
     function byFindler(){
         $api.openFile(function (res,err) {
            if(res){
                $api.showTips("tab2_tips","解析成功！");
                getApiInfo();
            } else {
                $api.showTips("tab2_tips",err.message);
            }
         });
     }
     function generateCodeAll(){
         $api.generateCodeAll(function(ret,err){
            if(ret){
                $api.showTips("tab2_tips",ret);
            }else{
                $api.showTips("tab2_tips",err.message);
            }
         });

     }



     //禁用右键
     document.oncontextmenu=function(e){
         return false;
     }
     //载入完成执行
     $api.onReady(function(){
         getAsFileInfo();
     });
     //tab切换
     function select(obj,index){
         $api.removeCls($api.dom(".tab.select"),'select');
         $api.addCls(obj,'select');
         $api.removeCls($api.dom(".content.select"),'select');
         var current = $api.byId("tab"+index);
         $api.addCls(current,'select');
         if($api.hasCls(current,'load')){
             return
         }
         $api.addCls(current,'load');
         switch (index) {
             case 1:
                 getAsFileInfo();
                 break
             case 2:
                 getDomainInfo();
                 getApiInfo();
                 break
             case 3:

                 break
             case 4:
                 initPage4();
                 break
         }
     }
     function initPage4(){
         $api.getStorage("qrcode",function(ret,err){
            if(ret){
                $api.val($api.byId("qrcode"),ret);
                qrcode(ret);
            }
         });
     }
     //获取android studio 当前打开的页面并获取view节点
     var fileInfo ;//AS文件信息
     function getAsFileInfo(){
         $api.getAsFileInfo(function(res,err){
             if(res){
                 fileInfo = res;
                 $api.html($api.byId('tab1_context'),'');
                 var layouts = fileInfo.layouts;
                 if(layouts&&layouts.length>0){
                     for(var i = 0 ;i<layouts.length;i++){
                         getView(layouts[i].path);
                     }
                 }
                 if(fileInfo.modelPath){
                     $api.html($api.byId('add_icon_tips'),'将在'+fileInfo.modelPath+'/res目录下自动裁剪各种规格的mipmap图片');
                 }else{
                     $api.html($api.byId('add_icon_tips'),'请在android studio里选择一个activity页面<button class="aui-btn" onclick="getAsFileInfo();">刷新</button>');
                 }
             }else{
                 $api.html($api.byId('tab1_context'),'<div class="layout aui-col-xs-12">' +
                     '<div class="aui-col-xs-10">'+err.message+'</div>' +
                     '<div class="aui-col-xs-2">' +
                     '<a class="aui-btn" style="float: right" onclick="getAsFileInfo();">刷新</a>' +
                     '</div></div>');
                 $api.html($api.byId('add_icon_tips'),'您未打开android studio<button class="aui-btn" onclick="getAsFileInfo();">刷新</button>');
             }
         });
     }
     function getView(path){
         $api.getView(path,function(res,err){
             if(res){
                 $api.append($api.byId('tab1_context'),JSON.stringify(res));
             }else{
                 alert(JSON.stringify(err));
             }
         });
     }
     var apiInfos ;
     var domains;
     var selectDomain;
     function getDomainInfo(){
         $api.getDomainInfo(function (res,err) {
             if(res){
                 domains = res;
             }else{

             }
         });
     }
     //加载api信息
     function getApiInfo(){
         $api.getApiInfo(selectDomain,hasDel,function(res,err){
             if(res){
                 apiInfos = res;
                 var html = $api.template("apiDom",res);
                 $api.html($api.byId("tab2_context"),html);
             }else{
                 tips("加载数据失败")
             }
         });
     }
     //获取android studio日志
     function getAsLog(){
         var log = $api.val($api.byId("log"));
         if(log==''){
             return;
         }
         $api.getAsLog(log,function(res,err){
             if(res){
                 var log = res;
                 var arr = new Array();
                 if(log.indexOf("}{")!=-1){
                     arr = getSpitArr(log,'}{');
                 }else if(log.indexOf("][")!=-1){
                     arr = getSpitArr(log,"][");
                 }else{
                     arr = getSpitArr(log,null);
                 }
                 var html = $api.template("apiLog",arr);
                 $api.html($api.byId("tab3_context"),html);
             }else{
                 alert(JSON.stringify(err));
             }

         });
     }
     //取出文本中的多组数组或对象放置到列表中
     function getSpitArr(str,split){
         var s = [str];
         var left,right;
         if(split!=null){
             s = str.split(split);
             left = split.substring(0,1);
             right = split.substring(split.length-1);
         }
         var arr = new Array();
         for(var i in s){
             var t = s[i];
             if(right!=undefined&&t.length>0&&t.substring(0,1)!=right){
                 t=right+t;
             }
             if(left!=undefined&&t.length>0&&t.substring(t.length-1)!=left){
                 t=t+left;
             }
             var d = {};
             d.text = t;
             arr.push(d);
         }
         return arr;
     }

     ////////////////////工具///////////////////
     function parseQrcode(){
         var code = $api.val($api.byId("qrcode"));
         if (!code) {
             $api.byId("qrcode").focus();
             return;
         }
         $api.setStorage("qrcode",code);
         qrcode(code);
     }
     function qrcode(data){
         $api.html($api.byId("qrcode_area"),'');
         new QRCode("qrcode_area", {
             text: data,
             width: 128,
             height: 128,
             colorDark : "#000000",
             colorLight : "#ffffff",
             correctLevel : QRCode.CorrectLevel.H
         });
     }
     function randomString(len) {
         len = len || 32;
         var $chars = 'ABCDEFGHJKMNPQRSTWXYZ1234567890';
         var maxPos = $chars.length;
         var pwd = '';
         for (i = 0; i < len; i++) {
             pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
         }
         pwd = "AAA11"+pwd.substring(5);
         return pwd;
     }
     var timeout ;
     function autoCode(){
         var code = randomString(13);
         qrcode(code);
         $api.val($api.byId("qrcode"),code);
         timeout = setTimeout(function(){
             autoCode();
         },400);
     }
     function removeAutoCode(){
         clearTimeout(timeout);
     }

     function fileSign(){
         $api.fileSign(function(ret,err){
            if(ret){
                $api.val($api.byId('fileSign'),ret);
            } else{
                $api.val($api.byId('fileSign'),err.message);
            }
         });
     }
     function addIcon(){
         var filename = $api.val($api.byId('addIcon'));
         $api.addIcon(filename,true,function(ret,err){
            if(ret){
                $api.showTips('add_icon_tips',ret);
            } else{
                tips(err.message);
            }
         });
     }

     function hideTips(){
         var tip = $api.byId("tips");
         if(!$api.hasCls(tip,"hide")){
             $api.addCls(tip,"hide");
         }
     }
     var tipsArr = new Array();
     function tips(str){
         tipsArr.push(str);
         $api.removeCls($api.byId("tips"),"hide");
         $api.html($api.byId("tip_msg"),str);
         setTimeout(function(){
             hideTips();
         },3000);
     }
     //处理回调
     function callback(method,data){
         $api.callback(method,data);
     }
 </script>
</body>
</html>